package com.example.testgit.mapstruct;

import com.example.testgit.VO.DormitoryRewardVO;
import com.example.testgit.entity.DormitoryRewardDO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.Named;
import org.mapstruct.factory.Mappers;

import java.util.List;

@Mapper
public interface DormitoryRewardConverter {

    DormitoryRewardConverter INSTANCE = Mappers.getMapper(DormitoryRewardConverter.class);

    @Mappings({
            @Mapping(source = "rewardType", target = "rewardType", qualifiedByName = "typeTrans"),
            @Mapping(source = "rewardTime", target = "rewardTime", dateFormat = "yyyy年MM月dd日")
    })
    DormitoryRewardVO toVO(DormitoryRewardDO dormitoryRewardDO);

    @Mappings({
            @Mapping(source = "rewardType", target = "rewardType", qualifiedByName = "typeTrans"),
            @Mapping(source = "rewardTime", target = "rewardTime", dateFormat = "yyyy年MM月dd日")
    })
    List<DormitoryRewardVO> toVOList(List<DormitoryRewardDO> dormitoryRewardDOList);

    @Named("typeTrans")
    default String typeTrans(Integer rewardType) {
        if (rewardType.equals(0)) return "获奖";
        else return "警告";
    }
}
